/*
 Copyright (C) 2010-2013. 
 Ezequiel Palumbo, Calipsoide FOSS Foundation.
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public License
 along with this program.  If not, see http://www.gnu.org/licenses/. 
 
 Email: contacto@ehpalumbo.com.ar 
*/

package org.calipsoide.dbf2xml.model;

import java.util.ArrayList;
import java.util.List;

/**
 * 
 * Representation of a row of a table. Has an ID number and a list of fields.
 * 
 * @since 1.0
 * @author ehpalumbo
 *
 */
public class Record {

	private Integer id;
	private List<Field> fields;

	/**
	 * Creates a record with its ID but no fields.
	 * 
	 * @param id number of the record
	 * 
	 */
	public Record(Integer id) {
		this(id, new ArrayList<Field>());
	}

	/**
	 * 
	 * Creates a record with its ID and its fields.
	 * 
	 * @param id number of the record
	 * @param fields list of fields in record
	 * 
	 */
	public Record(Integer id, List<Field> fields) {
		super();
		this.id = id;
		this.fields = fields;
	}

	public Integer getId() {
		return id;
	}

	public List<Field> getFields() {
		return fields;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((fields == null) ? 0 : fields.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Record other = (Record) obj;
		if (fields == null) {
			if (other.fields != null)
				return false;
		} else if (!fields.equals(other.fields))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Record [id=" + id + ", fields=" + fields + "]";
	}

}
